package com.shaliangapp;

import android.app.Activity;
import android.app.Application;
import android.graphics.drawable.BitmapDrawable;
import android.widget.Toast;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.maning.mndialoglibrary.MProgressDialog;
import com.maning.mndialoglibrary.MStatusDialog;

import java.util.HashMap;
import java.util.Map;

public class HUDProgressAndroid extends ReactContextBaseJavaModule {

    private MProgressDialog progressDialog = null;
    private MStatusDialog statusDialog = null;

    public HUDProgressAndroid(ReactApplicationContext reactContext) {
        super(reactContext);
    }


    @ReactMethod
    public void showWithStatus(String status) {
        Activity currentActivity = getCurrentActivity();
        if (currentActivity != null) {
            //默认
            MProgressDialog.showProgress(currentActivity, status);
        }
    }

    @ReactMethod
    public void dismiss(Callback callback) {
        Activity currentActivity = getCurrentActivity();
        if (currentActivity != null && MProgressDialog.isShowing()) {
            MProgressDialog.dismissProgress();
        }
        callback.invoke(MProgressDialog.isShowing());
    }

    @ReactMethod
    public void showSuccessWithStatus(String status) {
        Activity currentActivity = getCurrentActivity();
        if (currentActivity != null) {
            //默认
            if (this.statusDialog == null) {
                this.statusDialog = new MStatusDialog(currentActivity);
            }
            this.statusDialog.show(status, currentActivity.getResources().getDrawable(R.drawable.pa_success));
        }
    }

    @ReactMethod
    public void showErrorWithStatus(String status) {
        Activity currentActivity = getCurrentActivity();
        if (currentActivity != null) {
            //默认
            if (this.statusDialog == null) {
                this.statusDialog = new MStatusDialog(currentActivity);
            }
            this.statusDialog.show(status, currentActivity.getResources().getDrawable(R.drawable.error));

        }
    }

    @Override
    public String getName() {
        return "HUDProgress";
    }


}

